package goleetcode

import "math"

func maxStrength(nums []int) int64 {
	neg, zeroCnt, pos := 0, 0, 0
	prod := 1
	maxN := math.MinInt32

	for _, num := range nums {
		if num < 0 {
			neg++
			prod *= num
			if num > maxN {
				maxN = num
			}
		} else if num == 0 {
			zeroCnt++
		} else {
			prod *= num
			pos++
		}
	}

	if neg == 1 && zeroCnt == 0 && pos == 0 {
		return int64(nums[0])
	}

	if neg <= 1 && pos == 0 {
		return int64(0)
	}

	if prod < 0 {
        return int64(prod / maxN)
    } else {
        return int64(prod)
    }

}